//
//  LoginView.m
//  Diary
//
//  Created by lanou3g on 15/11/11.
//  Copyright © 2015年 王艺拓. All rights reserved.
//

#import "LoginView.h"

@implementation LoginView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addLoginView];
        [self setUpGesture];
    }
    return self;
}

- (void)addLoginView{
    // 用户名
    self.loginUserTextField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.frame)*0.1, CGRectGetHeight(self.frame)*0.35, CGRectGetWidth(self.frame)*0.8, CGRectGetWidth(self.frame)*0.1)];
    UIImageView *userLeft = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetHeight(self.loginUserTextField.frame), CGRectGetHeight(self.loginUserTextField.frame))];
    userLeft.image = [UIImage imageNamed:@"login_icon"];
    self.loginUserTextField.leftView = userLeft;
    self.loginUserTextField.leftViewMode = UITextFieldViewModeAlways;
    self.loginUserTextField.textColor = [UIColor colorWithRed:0.4 green:0.4 blue:0.4 alpha:1.0f];
    [self addSubview:self.loginUserTextField];
    UIView *userLineView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.loginUserTextField.frame), CGRectGetMaxY(self.loginUserTextField.frame), CGRectGetWidth(self.loginUserTextField.frame), 2)];
    userLineView.backgroundColor = [UIColor colorWithRed:0.25 green:0.25 blue:0.25 alpha:1];
    //[self addSubview:userLineView];
    
    // 密码
    self.loginPasswordTextField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.loginUserTextField.frame), CGRectGetMaxY(self.loginUserTextField.frame)+CGRectGetHeight(self.loginUserTextField.frame)*0.3, CGRectGetWidth(self.loginUserTextField.frame), CGRectGetHeight(self.loginUserTextField.frame))];
    UIImageView *passwordLeft = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetHeight(self.loginPasswordTextField.frame), CGRectGetHeight(self.loginPasswordTextField.frame))];
    self.loginPasswordTextField.textColor = [UIColor colorWithRed:0.4 green:0.4 blue:0.4 alpha:1.0f];
    passwordLeft.image = [UIImage imageNamed:@"password_icon"];
    self.loginPasswordTextField.leftView = passwordLeft;
    self.loginPasswordTextField.leftViewMode = UITextFieldViewModeAlways;
    self.loginPasswordTextField.secureTextEntry = YES;
    [self addSubview:self.loginPasswordTextField];
    UIView *passwordLineView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.loginPasswordTextField.frame), CGRectGetMaxY(self.loginPasswordTextField.frame) * 1.05, CGRectGetWidth(self.loginPasswordTextField.frame), 2)];
    passwordLineView.backgroundColor = [UIColor colorWithRed:0.4 green:0.4 blue:0.4 alpha:1];
    [self addSubview:passwordLineView];
    
    
    // 注册按钮
    self.loginRegisterButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.loginRegisterButton.frame = CGRectMake(CGRectGetMinX(self.loginUserTextField.frame), CGRectGetHeight(self.frame)*0.63, CGRectGetWidth(self.frame)*0.1*2, CGRectGetWidth(self.frame)*0.1*2);
    [self.loginRegisterButton setImage:[UIImage imageNamed:@"adding"] forState:UIControlStateNormal];
    [self addSubview:self.loginRegisterButton];
    
    // 登录按钮
    self.loginFinishButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.loginFinishButton.frame = CGRectMake(CGRectGetMaxX(self.loginUserTextField.frame) - CGRectGetWidth(self.loginRegisterButton.frame), CGRectGetMinY(self.loginRegisterButton.frame), CGRectGetWidth(self.loginRegisterButton.frame), CGRectGetHeight(self.loginRegisterButton.frame));
    [self.loginFinishButton setImage:[UIImage imageNamed:@"confirming"] forState:UIControlStateNormal];
    [self addSubview:self.loginFinishButton];
    
    // 取消按钮
    self.loginCancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.loginCancelButton.frame = CGRectMake(CGRectGetMaxX(self.loginFinishButton.frame)+CGRectGetWidth(self.frame)*0.05, CGRectGetMinY(self.loginFinishButton.frame), CGRectGetWidth(self.loginFinishButton.frame), CGRectGetHeight(self.loginFinishButton.frame));
    [self.loginCancelButton setImage:[UIImage imageNamed:@"canceling"] forState:UIControlStateNormal];
    //[self addSubview:self.loginCancelButton];
    
    
    
    
    
    
}

- (void)setUpGesture{
    UISwipeGestureRecognizer *swipedown = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipedown:)];
    swipedown.direction = UISwipeGestureRecognizerDirectionDown;
    [self addGestureRecognizer:swipedown];
}

- (void)swipedown:(UISwipeGestureRecognizer *)sender{
    [self.loginPasswordTextField resignFirstResponder];
    [self.loginUserTextField resignFirstResponder];
}



@end
